<?php
class Pages extends CI_Controller{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('User_model');
    }
    public function view($id,$page = 'home')
    {
        if(! file_exists(APPPATH.'views/pages/'.$page.'.php')){
            show_404();
        }

        // $data['count'] = 2;
        //读取文件，存json格式
        @$countInText = json_decode(file_get_contents('./num.json'));
        $count = $countInText->count?$countInText->count:0;
        $count++;
        $countInText = json_encode(array('count'=>$count),true);
        $data = array(
            'name'=>'tomJason',
            'title'=>ucfirst($page),
            'count'=>$count
        );
        $user = $this->User_model->user_select($id);
        $data['user'] = $user[0]['username'];
        $data['path'] = APPPATH;
        //打开文件
        $re = fopen('./num.json','w');
        //写入文件
        fwrite($re,$countInText);
        //关闭打开的文件
        fclose($re);

        $this->load->view('templates/header',$data);
        $this->load->view('pages/'.$page,$data);
        $this->load->view('custom/goods',$data);
        $this->load->view('templates/footer',$data);
    }
}
?>